from database_connection.index import Base, engine
from sqlalchemy.orm import relationship, backref
from sqlalchemy import Text, Column, Integer, ForeignKey


class Message(Base):
    __tablename__ = "Message"
    id = Column(Integer, nullable=False, primary_key=True, autoincrement=True, unique=True, comment="id")
    message = Column(Text, nullable=False)#用户的留言
    time = Column(Text, nullable=False)#留言时间
    admin_id = Column(Integer, ForeignKey('Admin.id'),nullable=False)

    admin = relationship('Admin', back_populates='message')
    def message_to_dict(self):
        return {
            'id': self.id,
            'message': self.message,
            'time':self.time,
            'admin_id': self.admin_id,
        }

    def __init__(self, message, time, admin_id):
        self.message = message
        self.time = time
        self.admin_id = admin_id

Base.metadata.create_all(engine)
